package com.study.study;

import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;

import com.common.base.fragment.BaseFragment;
import com.common.bean.InfoResult;
import com.common.theme.ColorPalette;
import com.common.ui.barlibrary.ImmersionBar;
import com.common.utils.AntiShake;
import com.common.utils.ApkUtils;
import com.common.utils.ColorUtil;
import com.orhanobut.hawk.Hawk;
import com.study.R;
import butterknife.BindView;
import butterknife.OnClick;

public class StudyFragment extends BaseFragment {
    @BindView(R.id.tv1)
    TextView tv1;
    @BindView(R.id.tv2)
    TextView tv2;

    @Override
    public boolean isImmersionBarEnabled() {
        return true;
    }

    @Override
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                //是否可以修改导航栏颜色，默认为true
                .navigationBarEnable(true)
                //导航栏颜色，不写默认黑色
                .navigationBarColor(R.color.black)
                .statusBarColor(R.color.statebar)
                //导航栏图标是深色，不写默认为亮色
                .navigationBarDarkIcon(true)
                //自动状态栏字体和导航栏图标变色，必须指定状态栏颜色和导航栏颜色才可以自动变色哦
                .autoDarkModeEnable(true)
                //解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                .fitsSystemWindows(true)
                .init();
    }

    @Override
    public View isSupportLoadSirEnabled() {
        return null;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_study;
    }

    @Override
    public void init() {

    }

    @Override
    public void loadData() {

    }

    @OnClick({R.id.tv1,R.id.tv2})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.tv1:
                //判断是否多次点击
                if (AntiShake.check(view.getId())) {
                    return;
                }
                int a = Color.parseColor("#F78AE0");

                int color = -11751600;
                int x = ColorPalette.getObscuredColor(color);


                int y = R.color.color4;

                String z = toHexEncoding(y);

                //tv1.setText("" + a + "@@@"+ x+ "@@@"+ y+ "@@@"+ z );

                int bb = R.color.md_blue_900;
                tv1.setText(""+ bb );

                //白色字体
                ApkUtils.getInstance().setAndroidNativeLightStatusBar(getActivity(),false);
                //白色图标
                ApkUtils.getInstance().setLightNavigationBar(getActivity(),false);
                tv1.setTextColor(color);
                break;
            case R.id.tv2:
                //判断是否多次点击
                if (AntiShake.check(view.getId())) {
                    return;
                }
                int b = R.color.md_blue_900;

                int c = ContextCompat.getColor(getActivity(), R.color.md_blue_900);

                int d = ColorUtil.getInstance().HextoColor("#0D47A1");

                int e = Color.parseColor("#0D47A1");

                int f = getContext().getColor(R.color.md_blue_900);
                int g = Integer.valueOf("0D47A1",16);

                tv2.setText("" + b + "@@@@"+ c + "@@" + d +"!!!!" + e + "f的只" + f + "g的在"+ g);
                //黑色字体
                ApkUtils.getInstance().setAndroidNativeLightStatusBar(getActivity(),true);
                //黑色图标
                ApkUtils.getInstance().setLightNavigationBar(getActivity(),true);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onSuccess(int what, InfoResult t) {

    }

    @Override
    protected void onFail(int what, InfoResult t) {

    }

    public String toHexEncoding(int color) {
        String R, G, B;
        StringBuffer sb = new StringBuffer();
        R = Integer.toHexString(Color.red(color));
        G = Integer.toHexString(Color.green(color));
        B = Integer.toHexString(Color.blue(color));
        //判断获取到的R,G,B值的长度 如果长度等于1 给R,G,B值的前边添0
        R = R.length() == 1 ? "0" + R : R;
        G = G.length() == 1 ? "0" + G : G;
        B = B.length() == 1 ? "0" + B : B;
        sb.append("0x");
        sb.append(R);
        sb.append(G);
        sb.append(B);
        return sb.toString();
    }
}
